package main

import (
	"bytes"
	"encoding/gob"
	"fmt"
	"log"
)

// 使用gob解析数据

type P struct {
	X, Y, Z int
	Name    string
}

type Q struct {
	X, Y *int32
	Name string
}

func main() {
	var network bytes.Buffer
	enc := gob.NewEncoder(&network) // 将写入到network
	dec := gob.NewDecoder(&network) // 将从network取出
	if err := enc.Encode(P{3, 3, 3, "cube"}); err != nil {
		log.Fatal("Encoding error: ", err)
	}
	var q Q
	if err := dec.Decode(&q); err != nil {
		log.Fatal("Decoding error: ", err)
	}
	fmt.Printf("%q: {%d, %d}\n", q.Name, q.X, q.Y)

}
